layui.use(['table', 'admin', 'ax', 'laytpl','jquery','form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laytpl = layui.laytpl;
    var form = layui.form;

    /**
     * 工程流水
     */
    var TaskFlow = {
        tableId: "taskFlowTable"
    };

    /**
     * 初始化表格的列
     */
    TaskFlow.initColumn = function () {
        return [[
            {field: 'id', hide: true, title: '工程id', fixed: true},
            {field: 'name', sort: true, title: '工程名称',align: "left", width: 200,  fixed: true},
            //开发总监
            //{field: 'kfzj', sort: true, title: '开发总监',align: "center", width: 200},
            {templet: '#kfzjTpl', sort: true, title: '开发总监',align: "center"},
            //2
            //{field: 'gczj', sort: true, title: '工程总监',align: "center", width: 200},
            {templet: '#gczjTpl', sort: true, title: '工程总监',align: "center"},
            //3
            //{field: 'yyzj', sort: true, title: '营运总监',align: "center",width: 160 },
            {templet: '#yyzjTpl', sort: true, title: '营运总监',align: "center"},
            //4
            // {field: 'allotYy', sort: true, title: '指定营运经理',align: "center",width: 160 },
            {templet: '#statusTpl1', sort: true, title: '指定营运经理',align: "center"},
            //5
            //{field: 'allotDd', sort: true, title: '指定督导',align: "center",width: 160},
            {templet: '#statusTpl2', sort: true, title: '指定督导',align: "center"},
            //6
            {field: 'dudao', sort: true, title: '督导',align: "center"},

            //7完工
            {field: 'gcb', sort: true, title: '完工',align: "center"},
            {templet: '#statusTpl3', sort: true, title: '是否开业',align: "center"},
                        {field: 'df', sort: true, title: '电费',align: "center"},
                        {field: 'zjoneyear', sort: true, title: '租金(第一年)',align: "center"},
            {align: 'center', toolbar: '#tableBar', title: '操作', align: "center", minWidth: 110}

        ]];
    };

    TaskFlow.tabCfg={
        elem: '#' + TaskFlow.tableId,
        even: true,
        data:[],
        page: true,
        cols: TaskFlow.initColumn()
    };
    var  para = sessionStorage.getItem("gccxList");
    if(para!=null){
        TaskFlow.tabCfg.url= Feng.ctxPath + '/task/productList';
        var p=JSON.parse(para);
        TaskFlow.tabCfg.where=p;
        if(p.name!=''){
            $('#condition').val(p.name);
        }
        if(p.openYn!=''){
            $('#openYn').val(p.openYn);
        }
        if(p.endYn!=''){
            $('#endYn').val(p.endYn);
        }
        if(p.cashierAccountYn!=''){
            $('#cashierAccountYn').val(p.cashierAccountYn);
        }
        form.render('select');
    }
    // 渲染表格
    var tableResult = table.render(TaskFlow.tabCfg);



    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        TaskFlow.search();
    });

    /**
     * 点击查询按钮
     */
    TaskFlow.search = function () {
        var queryData = {};
        queryData['name'] = $("#condition").val();
        queryData['openYn'] = $("#openYn").val();
        queryData['endYn'] = $("#endYn").val();
        queryData['cashierAccountYn'] = $("#cashierAccountYn").val();
        // table.reload(TaskFlow.tableId, {where: queryData});
        TaskFlow.tabCfg.url= Feng.ctxPath + '/task/productList';
        TaskFlow.tabCfg.where= queryData;
        table.render(TaskFlow.tabCfg);
        sessionStorage.setItem("gccxList",JSON.stringify(queryData));
    };


    TaskFlow.search();
    /**
     * 查看流水明细
     */
    TaskFlow.flowChart = function (data) {
        window.location.href = Feng.ctxPath + '/project/proFlowChart?id=' + data.id;
    };

    // 工具条点击事件
    table.on('tool(' + TaskFlow.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'flowChart') {
            TaskFlow.flowChart(data);
        }
    });
});
